package com.bjsxt.servic.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjsxt.commons.pojo.BaizhanResult;
import com.bjsxt.mapper.TbContentMapper;
import com.bjsxt.pojo.TbContent;
import com.bjsxt.servic.PortalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @author coder_z
 * @date 2023/3/13
 **/
@Service
public class PortalServiceImpl implements PortalService {
    @Autowired
    private TbContentMapper tbContentMapper;
//    防止开发环境和生产环境大广告主键更改，定义软编码
    @Value("${baizhan.mysql.bigad.id}")
    private long bigadId;
    @Cacheable(cacheNames ="com.bjsxt",key ="'bigad'")
    @Override
    public BaizhanResult showBigAd() {
        System.out.println("没缓存");
//        按照更新时间查找最新6条数据
        Page<TbContent> page = new Page<TbContent>(1, 6);
//        条件
        QueryWrapper<TbContent> wrapper = new QueryWrapper<TbContent>().eq("category_id", bigadId);
//        按照更新时间
        wrapper.orderByDesc("updated");
        Page<TbContent> pageResult = tbContentMapper.selectPage(page, wrapper);
        return BaizhanResult.ok(pageResult.getRecords());
    }
}
